<template>
  <div class="app-container">
    <el-form
      ref="queryForm"
      :model="queryParams"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="操作人" prop="operaUserName">
        <el-input
          v-model="queryParams.operaUserName"
          placeholder="请输入操作人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="患者姓名" prop="operaTargetName">
        <el-input
          v-model="queryParams.operaTargetName"
          placeholder="请输入患者姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作时间" prop="operaTime">
        <el-date-picker
          v-model="queryParams.operaTime"
          clearable
          size="small"
          style="width: 200px"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择操作时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="small"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      border
      :data="logList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="操作人姓名" align="center" prop="operaUserName" />
      <el-table-column
        label="操作对象名称"
        align="center"
        prop="operaTargetName"
      />
      <el-table-column
        label="操作时间"
        align="center"
        prop="operaTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.operaTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作文字" align="center" prop="operaText" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { useroperaListLog } from '@/api/erp/log'

export default {
  name: 'Log',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 操作日志表格数据
      logList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        type: '修改黄页',
        operaTargetName: undefined,
        operaUserName: undefined,
        operaTime: undefined,
      },
    }
  },
  created() {
    this.getList()
    const { pageNum } = this.$route.query
    this.queryParams.pageNum = pageNum
  },
  methods: {
    /** 查询操作日志列表 */
    getList() {
      this.loading = true
      useroperaListLog(this.queryParams).then((response) => {
        this.logList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
  },
}
</script>
